home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
progjour
/
1991
/
06
/
alib
/
setarg.asm
< prev
next >
Wrap
Assembly Source File
|
1991-06-25
|
2KB
|
132 lines
title set argc argv
include asm.inc
public read_command_line
public read_environment
public set_argc_argv
public strskp_white
.data
extw psp
.data?
public argc,argv
argc dw ?
argv dd ?
.code
extn malloc,ms_dos,strcpy,strskp
;; read command line
;
; exit DS:SI program command line
;
read_command_line proc
mov ds,psp[bp]
mov si,81h
ret
read_command_line endp
;; read environment
;
; exit DS:SI environment
;
read_environment proc
xor si,si
mov ds,psp[bp]
mov ds,[si+2Ch]
ret
read_environment endp
;; set argc argv
;
; exit Cf if no memory
; uses AX,CX,DI,SI,ES,DS
;
set_argc_argv proc
mov cx,256
call malloc
jc saa9 ; if no memory
mov argc[bp],1
mov wptr argv[bp],di
mov wptr argv[bp+2],es
mov ah,30h
call ms_dos
cmp al,3
jb saa10 ; if prior to DOS version 3.x
call read_environment ; skip environment
saa1: call strskp
lodsb
cmp al,NULL_CHAR
jne saa1
lodsw ; (skip 1)
call strcpy ; copy program name which appears
inc di ; after environment
saa2: call read_command_line
saa3: call strskp_white
cmp al,CR_CHAR
je saa7 ; if no more arguments
inc argc[bp]
jmp saa5
saa4: stosb
saa5: lodsb
cmp al,SPACE_CHAR
jbe saa6
cmp al,','
je saa6
cmp al,'~'
jbe saa4
saa6: cmp al,CR_CHAR
mov al,NULL_CHAR
stosb
jne saa3
saa7: inc di ; word align table
and di,-2
lds si,argv[bp] ; get ptr to first argument
mov wptr argv[bp],di ; set pointer list offset
mov cx,argc[bp] ; get list count (cannot==0)
saa8: mov ax,si ; build pointer list
stosw
call strskp
loop saa8
clc
saa9: ret
saa10: mov ax,'C'
stosw
jmp saa2
set_argc_argv endp
;; strskp white
;
; entry DS:SI text ptr
; exit SI updated past spaces and tabs
; AL non-white character
;
strskp_white proc
lodsb
cmp al,SPACE_CHAR
je strskp_white
cmp al,TAB_CHAR
je strskp_white
dec si
ret
strskp_white endp
end